home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 3_16.lha / 3_16 / 3_16a.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  783b  |  45 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / Strip all C++ comments
  6. / from a source file read
  7. / on the standard input.
  8. include <stream.h>
  9.  
  10. nt main(int, char**)
  11.  
  12.    char ch;
  13.  
  14.    while (cin.get(ch))
  15. {
  16. // a / may be followed by another / or a *
  17. if (ch == '/')
  18.     {
  19.     cin.get(ch);
  20.     if (!cin)
  21.     break;
  22.  
  23.     if (ch == '/')    dolinecomment();
  24.     else if (ch == '*')    doblockcomment();
  25.  
  26.     // if not one of the above, then it's
  27.     // not a comment and the 2nd character
  28.     // must be rescanned
  29.     else
  30.     {
  31.     cout.put('/');
  32.     cin.putback(ch);
  33.     }
  34.     }
  35.  
  36. else            // a printable character
  37.     {
  38.     cout.put(ch);
  39.     if (ch == '"' || ch == '\'')
  40.     do_string_or_char(ch);
  41.     }
  42. }
  43.    return 0;
  44.  
  45.